//
//  HomePageModel.swift
//
//  Created by eme on 2016/12/13
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON
import ModelProtocol

enum HomePageType{
    case  lbt  ///轮播图
    case  ptfl /// 平台分类
    case  pps  /// 品牌商
    case  sp   /// 商品 为3
}
extension HomePageType{
    var value: Int {
        switch self {
        case .lbt:
            return 1
        case .ptfl:
            return 2
        case .pps:
            return 3
        case .sp:
            return 4
        }
    }
}
 class HomePageModel: ModelProtocol {

    // MARK: Declaration for string constants to be used to decode and also serialize.
	internal let kHomePageTitleKey: String = "title"
	internal let kHomePageImgKey: String = "img"
	internal let kHomePageShowtypeKey: String = "showtype"
	internal let kHomePageInternalIdentifierKey: String = "id"
	internal let kHomePageTypeKey: String = "type"


    // MARK: 属性
	 var title: String
	 var img: String
	 var showtype: String
	 var internalIdentifier: Int
	 var type: Int
     var data:JSON
    var istimeby:String
    var list:[AnyObject]


    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
		title = json[kHomePageTitleKey].stringValue
		img = json[kHomePageImgKey].stringValue
		showtype = json[kHomePageShowtypeKey].stringValue
		internalIdentifier = json[kHomePageInternalIdentifierKey].intValue
		type = json[kHomePageTypeKey].intValue
        istimeby = json["istimeby"].stringValue
        data = json["data"]
        
        switch self.type {
        case HomePageType.lbt.value:
            self.list = self.data.arrayValue.flatMap { CpImageModel(json: $0) }
        case HomePageType.ptfl.value:
            self.list = self.data.arrayValue.flatMap { ProductCategoryModel(json: $0) }
        case HomePageType.pps.value:
            self.list = self.data.arrayValue.flatMap { HpBrandModel(json: $0) }
        case HomePageType.sp.value:
            self.list = self.data.arrayValue.flatMap { HpProductModel(json: $0) }
        default:
            self.list = []
        }

    }


    /**
    Generates description of the object in the form of a NSDictionary.
    - returns: A Key value pair containing all valid values in the object.
    */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {

        var dictionary: [String : AnyObject ] = [ : ]

			dictionary.updateValue(title as AnyObject, forKey: kHomePageTitleKey)

			dictionary.updateValue(img as AnyObject, forKey: kHomePageImgKey)

			dictionary.updateValue(showtype as AnyObject, forKey: kHomePageShowtypeKey)

			dictionary.updateValue(internalIdentifier as AnyObject, forKey: kHomePageInternalIdentifierKey)

			dictionary.updateValue(type as AnyObject, forKey: kHomePageTypeKey)


        return dictionary
    }


}
